package com.ysx.search.controller;

import com.ysx.common.pojo.PageInfo;
import com.ysx.common.pojo.Result;
import com.ysx.search.document.ArticleInfoDocument;
import com.ysx.search.dto.SearchDto;
import com.ysx.search.service.ArticleInfoDocumentSearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/article")
public class SearchController {

    @Autowired
    private ArticleInfoDocumentSearchService articleInfoDocumentSearchService;

    /**
     * 分页查询
     *
     * @param searchDto
     * @return
     */
    @PostMapping("/search")
    public Result<PageInfo<ArticleInfoDocument>> search(@RequestBody SearchDto searchDto) {
        PageInfo<ArticleInfoDocument> articleInfo = articleInfoDocumentSearchService.search(searchDto);
        return Result.ok(articleInfo);
    }

    /**
     * 添加信息
     *
     * @param articleInfoDocument
     * @return
     */
    @PostMapping("/save")
    public Result saveToEs(@RequestBody ArticleInfoDocument articleInfoDocument) {
        articleInfoDocumentSearchService.save(articleInfoDocument);
        return Result.ok();
    }

}